package com.ruoyi.workflow.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.workflow.context.FlowableCallbackContext;
import com.ruoyi.workflow.service.IFlowableCallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/flowable/callback")
public class FlowableCallbackController extends BaseController {

    @Autowired
    private FlowableCallbackContext flowableCallbackContext;

    @PostMapping("/callBusiness")
    public Map<String,Object> callBusiness(@RequestBody Map<String,Object> callback){
        String serviceName = (String)callback.get("serviceName");
        Map<String,Object> result = null;
        if(StringUtils.isNotEmpty(serviceName)){
            IFlowableCallbackService flowableCallbackServiceImpl = flowableCallbackContext.getResource((String)callback.get("serviceName"));
            result = flowableCallbackServiceImpl.callbackBusinessApp(callback);
        }
        return result;
    }
}
